<?php

namespace Biz\service\adCalendar;

use Biz\cache\advertisement\CAdCounter;
use Biz\model\advertisement\MHhzAdmin;
use Biz\model\advertisement\MHhzDepartment;

class AdPositionData
{

    const OCCUPIED_START = ['每日', '每周一', '每周二', '每周三', '每周四', '每周五', '每周六', '每周日'];
    protected static array $admin_info = [];

    public static function adminInfo($admin_id): MHhzAdmin
    {
        if (empty(self::$admin_info[$admin_id])) {
            self::$admin_info[$admin_id] = new MHhzAdmin(MHhzAdmin::get('*', ['id' => $admin_id]));
            self::$admin_info[$admin_id]->department = new MHhzDepartment(MHhzDepartment::get('*', ['id' => self::$admin_info[$admin_id]->department_id]));
        }
        return self::$admin_info[$admin_id];
    }

    public static function getStartDay($format = true)
    {
        $v = CAdCounter::getOccupied();
        if ($format) return self::OCCUPIED_START[$v] ?? 0;
        return $v;
    }

    public static function setStartDay($v)
    {
        $key = array_search($v, self::OCCUPIED_START);

        if ($key !== false) CAdCounter::setOccupied($key);
    }
}